package io.renren.modules.xsl.controller;

import com.alibaba.fastjson.JSONObject;
import io.renren.modules.xsl.service.XslOrgService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

/**
 * 薪事力组织架构接口
 */
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/open-api")
@Tag(name = "薪事力-获取组织架构信息")
public class XslOrgController {

    private final static Logger logger = LoggerFactory.getLogger(XslOrgController.class);

    @Autowired
    private XslOrgService xslOrgService;

    @ResponseBody
    @RequestMapping("getDepartment")
    public String getDepartment(HttpServletRequest request, HttpServletResponse response) {

        JSONObject jsonObject = new JSONObject();
        try {
            try {
                Map<String, Object> map = xslOrgService.getDepartmentFindAll();
                jsonObject.put("success", true);
                jsonObject.put("data", map);
                jsonObject.put("message", "请求成功");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        } catch (Exception e) {
            logger.error("接口异常", e);
            jsonObject.put("error", e);
            jsonObject.put("message", e.getMessage());
        }
        return jsonObject.toJSONString();
    }
}